// 导入需要的config和request
import confing from '../../config/config.js';
import request from '../../util/request.js';


// 申明请求对象
const vendorRequest = {
    // vendor请求的基本url
    BASE_URL: confing.SYS_URL + "/vendor",

    list(page = 1, limit = 10, vendor, callbcak) {
        // url
        let url = this.BASE_URL + "/list?page=" + page + "&limit=" + limit;
        if (vendor) {
            if (vendor.vendorCode) {
                url += "&vendorCode=" + vendor.vendorCode;
            }
            if (vendor.vendorName) {
                url += "&vendorName=" + vendor.vendorName;
            }
            if (vendor.vendorNick) {
                url += "&vendorNick=" + vendor.vendorNick;
            }
            if (vendor.vendorEn) {
                url += "&vendorEn=" + vendor.vendorEn;
            }
            if (vendor.enableFlag) {
                url += "&enableFlag=" + vendor.enableFlag;
            }
        }
        // 发送请求
        request.get(url, callbcak);
    },

    /**
* 保存供应商
* @param {*} vendor  供应商对象
* @param {*} callback  回调函数
*/
    saveVendor(vendor, callback) {
        let url = this.BASE_URL + "/save";
        request.post(url, vendor, callback);
    },


    /**
 * 根据id加载供应商信息
 * @param {*} vendorId 供应商编号
 * @param {*} callback 回调函数
 */
    get(vendorId, callback) {
        if (vendorId) {
            // 准备url
            let url = this.BASE_URL + "/get?vendorId=" + vendorId;
            request.get(url, callback);
        }
        // 如果没有vendorId，不做任何处理
    },
    /**
 * 根据ID编辑供应商信息
 * @param {} vendor 
 * @param {*} callback  
 */
    edit(vendor, callback) {
        if (vendor != undefined && vendor.vendorId != undefined) {
            request.put(this.BASE_URL + "/update", vendor, callback);
        }
    },


            /**
     * 根据ID删除供应商
     * @param {*} vendorId 
     * @param {*} callback 
     */
            delete(vendorId,callback){
                request.delete(this.BASE_URL + "/" + vendorId,callback);
            },
    


}
// 将vendorRequest暴漏出去
export default vendorRequest;